/**
 * 警示教训部门 编辑页
 *
 * 作者 wanghw
 * 日期 2024-08-20 09:23:14
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#hazardCautionaryDept-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (hazardCautionaryDeptData) {
            form.val("hazardCautionaryDept-edit-form", {
                "cautionaryDeptId": hazardCautionaryDeptData.cautionaryDeptId,
                "tenantId": hazardCautionaryDeptData.tenantId,
                "reportId": hazardCautionaryDeptData.reportId,
                "deptId": hazardCautionaryDeptData.deptId,
                "deptName": hazardCautionaryDeptData.deptName,
                "learnDate": hazardCautionaryDeptData.learnDate,
                "learnStatus": hazardCautionaryDeptData.learnStatus,
                "noticeDate": hazardCautionaryDeptData.noticeDate,
            });
        }
    }

    form.on('submit(hazardCautionaryDept-edit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        if (data.cautionaryDeptId && data.cautionaryDeptId.length > 0) {
            febs.postArray(ctx + 'hazardCautionaryDept/update', data, function () {
                layer.closeAll();
                febs.alert.success('修改成功');
                febs.reloadPage();
            });
        } else {
            febs.postArray(ctx + 'hazardCautionaryDept', data, function () {
                layer.closeAll();
                febs.alert.success('新增成功');
                $('#febs-hazardCautionaryDept').find('#query').trigger('click');
            });
        }
    }
});